﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProductionManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProductionManagement.ProdArchiveDataVMs
{
    public partial class ProdArchiveDataListVM : BasePagedListVM<ProdArchiveData_View, ProdArchiveDataSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProdArchiveData_View>> InitGridHeader()
        {
            return new List<GridColumn<ProdArchiveData_View>>{
                
                this.MakeGridHeader(x => x.ProdArchiveData_ArchiveId).SetTitle(@Localizer["Page.数据源"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_Sn).SetTitle(@Localizer["Page.追溯码"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_Wo).SetTitle(@Localizer["Page.工单"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_ProductId).SetTitle(@Localizer["Page.产品号"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_ProductCode).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_OpId).SetTitle(@Localizer["Page.工位号"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_OpCode).SetTitle(@Localizer["Page.工位编号"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_DataTag).SetTitle(@Localizer["Page.变量名称"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_DataName).SetTitle(@Localizer["Page.数据名称"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_UpLimit).SetTitle(@Localizer["Page.数据上限"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_DataValue).SetTitle(@Localizer["Page.数据值"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_LowerLimit).SetTitle(@Localizer["Page.数据下限"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_SetParameter).SetTitle(@Localizer["Page.设置参数"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.ProdArchiveData_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProdArchiveData_View> GetSearchQuery()
        {
            var query = DC.Set<ProductionArchiveData>()
                
                .CheckEqual(Searcher.ArchiveIdId, x=>x.ArchiveIdId)
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckContain(Searcher.Wo, x=>x.Wo)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductCode, x=>x.ProductCode)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckContain(Searcher.DataTag, x=>x.DataTag)
                .CheckContain(Searcher.DataName, x=>x.DataName)
                .CheckEqual(Searcher.UpLimit, x=>x.UpLimit)
                .CheckContain(Searcher.DataValue, x=>x.DataValue)
                .CheckEqual(Searcher.LowerLimit, x=>x.LowerLimit)
                .CheckContain(Searcher.SetParameter, x=>x.SetParameter)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProdArchiveData_View
                {
				    ID = x.ID,
                    
                    ProdArchiveData_ArchiveId = x.ArchiveId.TenantCode,
                    ProdArchiveData_Sn = x.Sn,
                    ProdArchiveData_Wo = x.Wo,
                    ProdArchiveData_ProductId = x.ProductId,
                    ProdArchiveData_ProductCode = x.ProductCode,
                    ProdArchiveData_OpId = x.OpId,
                    ProdArchiveData_OpCode = x.OpCode,
                    ProdArchiveData_DataTag = x.DataTag,
                    ProdArchiveData_DataName = x.DataName,
                    ProdArchiveData_UpLimit = x.UpLimit,
                    ProdArchiveData_DataValue = x.DataValue,
                    ProdArchiveData_LowerLimit = x.LowerLimit,
                    ProdArchiveData_SetParameter = x.SetParameter,
                    ProdArchiveData_CreateTime = x.CreateTime,
                    ProdArchiveData_UpdateTime = x.UpdateTime,
                    ProdArchiveData_CreateBy = x.CreateBy,
                    ProdArchiveData_UpdateBy = x.UpdateBy,
                    ProdArchiveData_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProdArchiveData_View: ProductionArchiveData
    {
        
        public string ProdArchiveData_ArchiveId { get; set; }
        public string ProdArchiveData_Sn { get; set; }
        public string ProdArchiveData_Wo { get; set; }
        public long? ProdArchiveData_ProductId { get; set; }
        public string ProdArchiveData_ProductCode { get; set; }
        public long? ProdArchiveData_OpId { get; set; }
        public string ProdArchiveData_OpCode { get; set; }
        public string ProdArchiveData_DataTag { get; set; }
        public string ProdArchiveData_DataName { get; set; }
        public decimal? ProdArchiveData_UpLimit { get; set; }
        public string ProdArchiveData_DataValue { get; set; }
        public decimal? ProdArchiveData_LowerLimit { get; set; }
        public string ProdArchiveData_SetParameter { get; set; }
        public DateTime? ProdArchiveData_CreateTime { get; set; }
        public DateTime? ProdArchiveData_UpdateTime { get; set; }
        public string ProdArchiveData_CreateBy { get; set; }
        public string ProdArchiveData_UpdateBy { get; set; }
        public bool ProdArchiveData_IsValid { get; set; }

    }

}